# Main tex file (without tex extension)
SRC=proposal


# Commands and options
TEX=xelatex
BIB=bibtex
XINDY=xindy

# Output PDF minor version
PDFMINORVER=5

# Specified xdvipdfmx to set PDF minor version from default (4) to another version. -E option: allways embed fonts regardless of lice. -halt-on-error
TEXOPTIONS=-halt-on-error -interaction=nonstopmode -synctex=-1 -output-driver='xdvipdfmx -E -V $(PDFMINORVER) ' 

# Included tex files (not the main file)
TEX0= glossaries.tex glossary_style.tex glossary_style-tl2009.tex commands.tex \
	abstract_en.tex abstract_fa.tex cover_en.tex cover_fa.tex jeld_info.tex taeid.tex \
	chap1.tex chap2.tex chap3.tex chap4.tex \
	appnd1.tex appnd2.tex \
	references.tex

# Biblography items
BIB0=references.bib IEEEtran_biboptions.bib

IMAGES=images

# Other files and folders (for backup)
OTHER=README IEEEtranSA.bst

all: $(SRC).pdf

# Build the main file
$(SRC).pdf: $(SRC).tex $(TEX0) $(BIB0) Makefile
	rm -fv $(SRC).pdf $(SRC).bbl *.gls *.glo
	$(TEX) $(TEXOPTIONS) $<
	$(BIB) $(SRC)
	$(XINDY) --language persian --codepage utf8 --input-markup xindy --module $(SRC) --log-file $(SRC).fa.glg --out-file $(SRC).fa.gls $(SRC).fa.glo
	$(XINDY) --language english --codepage utf8 --input-markup xindy --module $(SRC) --log-file $(SRC).en.glg --out-file $(SRC).en.gls $(SRC).en.glo
	$(TEX) $(TEXOPTIONS) $<
	while grep --fixed-strings "Rerun to" $(SRC).log ; do $(TEX) $(TEXOPTIONS) $< ; done
	@echo "===========================\nWarnings:\n"
	@grep 'Warning\|Error\|Underful\|Overful' $(SRC).log | sort

clean:
	rm -fv $(SRC).pdf *.log *.aux *.bbl *.blg *.out *.dvi *.synctex *.toc *.lof *.lot *.maf *.mtc* *.glg *.glo *.gls $(SRC).xdy *~ images/*~

backup:
	tar -cjf backups/$(SRC)-`date +%F_%H-%M-%S`.tar.bz2 Makefile $(SRC).tex $(SRC).pdf $(BIB0) $(TEX0) $(IMAGES) README

# PHONY targets
.PHONY : all view clean backup 